package com.jneagle.xlstool.bzwgjmx.impl.handler;

import com.dwarfeng.subgrade.stack.bean.key.LongIdKey;
import com.jneagle.xlstool.bzwgjmx.stack.bean.entity.RawPartData;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class V15RawDataRowParser extends AbstractRawDataRowParser {

    private static final String PARSER_NAME = "V15";

    @Value("${raw_data.parser.v15.pattern_index.project_no}")
    private int projectNoIndex;
    @Value("${raw_data.parser.v15.pattern_index.part_no}")
    private int partNoIndex;
    @Value("${raw_data.parser.v15.pattern_index.classification_name}")
    private int classificationNameIndex;
    @Value("${raw_data.parser.v15.pattern_index.production_name}")
    private int productionNameIndex;
    @Value("${raw_data.parser.v15.pattern_index.specification}")
    private int specificationIndex;
    @Value("${raw_data.parser.v15.pattern_index.demand}")
    private int demandIndex;
    @Value("${raw_data.parser.v15.pattern_index.remark}")
    private int remarkIndex;

    public V15RawDataRowParser() {
        super(PARSER_NAME);
    }

    @SuppressWarnings("DuplicatedCode")
    @Override
    public RawPartData parseRow(LongIdKey rawPartKey, int rowIndex, String rowContent) {
        // 以 \t 分割行内容。
        String[] contents = rowContent.split("\t", 10);

        String projectNo = contents[projectNoIndex];
        String partNo = contents[partNoIndex];
        String classificationName = contents[classificationNameIndex];
        String productionName = contents[productionNameIndex];
        String specification = contents[specificationIndex];
        String demand = contents[demandIndex];
        String remark = contents[remarkIndex];

        return new RawPartData(
                null, rawPartKey, projectNo, partNo, classificationName, productionName, specification, demand, remark,
                rowIndex);
    }
}
